package org.example.myleet.p1089;

import java.util.LinkedList;
import java.util.Queue;

public class Solution {
    public void duplicateZeros(int[] arr) {
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 1; i < arr.length; ++i) {
            queue.offer(arr[i]);
            if (arr[i - 1] == 0) {
                arr[i] = 0;
                ++i;
                if (i < arr.length) {
                    queue.offer(arr[i]);
                    arr[i] = queue.poll();
                }
            } else {
                arr[i] = queue.poll();
            }
        }
    }
}
